//获取坐标
function getTouchPosition(e) {
	e = e.originalEvent || e; //jquery wrap the originevent
	if(e.type === 'touchstart' || e.type === 'touchmove' || e.type === 'touchend') {
		return {
			x: e.targetTouches[0].pageX,
			y: e.targetTouches[0].pageY
		};
	} else {
		return {
			x: e.pageX,
			y: e.pageY
		};
	}
}

function isRealNum(val) {
	if(val == '' || val == null) {
		return false;
	}

	if(!isNaN(val)) {
		return true;
	} else {
		return false;
	}
}

function splitArr(str) {
	var arr = [];
	var len = str.length;
	for(var i = 0; i < len; i++) {
		arr.push(str.substr(i, 1));
	}
	return arr;
}
//yyyy-MM-dd HH:mm:ss
function getNowFormatDate() {
	var date = new Date();
	var seperator1 = "-";
	var seperator2 = ":";
	var month = date.getMonth() + 1;
	var strDate = date.getDate();
	if(month >= 1 && month <= 9) {
		month = "0" + month;
	}
	if(strDate >= 0 && strDate <= 9) {
		strDate = "0" + strDate;
	}
	var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate +
		" " + date.getHours() + seperator2 + date.getMinutes() +
		seperator2 + date.getSeconds();
	return currentdate;
}

function getNowForPicker() {
	var date = new Date();
	var seperator1 = "-";
	var seperator2 = ":";
	var month = date.getMonth() + 1;
	var strDate = date.getDate();
	if(month >= 1 && month <= 9) {
		month = "0" + month;
	}
	if(strDate >= 0 && strDate <= 9) {
		strDate = "0" + strDate;
	}
	var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate +
		" " + date.getHours() + seperator2 + date.getMinutes();
	return currentdate;
}

//十六进制颜色值域RGB格式颜色值之间的相互转换

//-------------------------------------
//十六进制颜色值的正则表达式
var reg = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/;
/*RGB颜色转换为16进制*/
String.prototype.colorHex = function() {
	var that = this;
	if(/^(rgb|RGB)/.test(that)) {
		var aColor = that.replace(/(?:\(|\)|rgb|RGB)*/g, "").split(",");
		var strHex = "#";
		for(var i = 0; i < aColor.length; i++) {
			var hex = Number(aColor[i]).toString(16);
			if(hex ===
				"0") {
				hex
					+= hex;
			}
			strHex
				+= hex;
		}
		if(strHex.length !==
			7) {
			strHex
				= that;
		}
		return strHex;
	} else if(reg.test(that)) {
		var aNum = that.replace(/#/, "").split("");
		if(aNum.length ===
			6) {
			return that;
		} else if(aNum.length ===
			3) {
			var numHex = "#";
			for(var i = 0; i < aNum.length; i += 1) {
				numHex
					+= (aNum[i] + aNum[i]);
			}
			return numHex;
		}
	} else {
		return that;
	}
};

//-------------------------------------------------

/*16进制颜色转为RGB格式*/
String.prototype.colorRgb = function() {
	var sColor = this.toLowerCase();
	if(sColor &&
		reg.test(sColor)) {
		if(sColor.length ===
			4) {
			var sColorNew = "#";
			for(var i = 1; i < 4; i += 1) {
				sColorNew
					+= sColor.slice(i, i + 1).concat(sColor.slice(i, i + 1));
			}
			sColor
				= sColorNew;
		}
		//处理六位的颜色值
		var sColorChange = [];
		for(var i = 1; i < 7; i += 2) {
			sColorChange.push(parseInt("0x" + sColor.slice(i, i + 2)));
		}
		return "RGB(" +
			sColorChange.join(",") +
			")";
	} else {
		return sColor;
	}
};

String.prototype.colorRgba = function(transparent) {
	var sColor = this.toLowerCase();
	if(sColor &&
		reg.test(sColor)) {
		if(sColor.length ===4) {
			var sColorNew = "#";
			for(var i = 1; i < 4; i += 1) {
				sColorNew += sColor.slice(i, i + 1).concat(sColor.slice(i, i + 1));
			}
			sColor = sColorNew;
		}
		//处理六位的颜色值
		var sColorChange = [];
		for(var i = 1; i < 7; i += 2) {
			sColorChange.push(parseInt("0x" + sColor.slice(i, i + 2)));
		}
		if(!transparent || transparent > 1 || transparent < 0) transparent = 1;
		return "RGBA(" +sColorChange.join(",") +","+ transparent +")";
	} else {
		return sColor;
	}
};


//获取url中的参数
function getUrlParam(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
    var r = window.location.search.substr(1).match(reg);  //匹配目标参数
    if (r != null) return unescape(r[2]);
    return null; //返回参数值
}